var but;
var premium=false;
if(!document.body.innerHTML.match(/What are the benefits for/i)){
	but=document.getElementById("content-inner").childNodes[1].childNodes[1];
	if(but.tagName==='IFRAME')but=document.getElementById("content-inner").childNodes[3].childNodes[5];
	but['data-href']=but.href;
	but.href=null;
	but.onClick=function(){
		return false
	};
	premium=true;
}else{
	$('.btn').each(function(){
		if($(this).html()=='Download'){
			but=this;
		}
	});
}
var box=document.createElement("div");
box.style.backgroundColor="#191919";
box.style.color="#FFFFFF";
box.style.width="100%";
box.style.height="100%";
box.style.position="absolute";
box.style.top="0";
box.style.left="0";
box.style.textAlign="center";
box.style.fontSize="12px";
box.style.fontFamily="'Lucida Grande', Arial, Helvetica, sans-serif";
box.style.zIndex="10000";
document.body.appendChild(box);
var logo=document.createElement("div");
logo.style.paddingTop="50px";
logo.align='center';
box.appendChild(logo);
logo.innerHTML="<img src='http://sc.cuevana.tv/new/img/logo.png' />";
var box2=document.createElement("div");
box2.style.paddingTop="50px";
box.appendChild(box2);
document.body.style.overflow="hidden";
if(document.getElementById('download-header').innerHTML.match(/Invalid security token/i)){
	box2.innerHTML="El archivo ha sido eliminado de Bayfiles.";
}else if(document.getElementById('content-inner').innerHTML.match(/has recently downloaded a file/i)){
	box2.innerHTML="Tu IP recientemente ha descargado algo de Bayfiles. Adquiere una cuenta premium en Bayfiles o espera 5 minutos.";
}else if(document.getElementById('content-inner').innerHTML.match(/already downloading/i)){
	box2.innerHTML="Tu IP se encuentra descargando algo de Bayfiles en este momento. Adquiere una cuenta premium en Bayfiles para descargas simultÃ¡neas.";
}else if(but){
	box2.appendChild(but);
	but.innerHTML="Click aquÃ­ para cargar el video";
	styleButton(but)
	if(premium){clickBut();
	}else{
		but.addEventListener("click",clickBut,false);
	}
}
function clickBut(){
	if(!premium)but.removeEventListener("click",clickBut,false);
	box2.innerHTML="Cargando...";
	if(premium){
		redirectLink(but['data-href']);
		return false;
	}else{
		setTimeout("getCaptcha()",200);
	}
}
function getCaptcha(){
	if(document.getElementById("ol-limited-content").style.display!="none"&&document.getElementById("counter")){
		var m=parseInt(document.getElementById("countDown").innerHTML);
		if(m>1){
			box2.innerHTML="Por favor, espera "+document.getElementById("countDown").innerHTML+" segundos";
		}else{
			box2.innerHTML="Cargando...";
			setTimeout("getCaptcha()",1500);
			return;
		}
	}else if(document.getElementById("content-inner").lastChild.lastChild.type=="button"){
		getFinalLink();return;
	}
	setTimeout("getCaptcha()",500);
}
function getFinalLink(){
	var p=document.getElementById("content-inner").lastChild.lastChild;if(p.type=="button"){
		var j=p.getAttribute('onclick');
		var a=j.substring(j.indexOf("'")+1,j.length-2);
		redirectLink(a);
		return;
	}
	setTimeout("getFinalLink()",500);
}
function redirectLink(a){
	var hashes=window.location.href.slice(window.location.href.indexOf('?')+ 1).replace(/amp;/gi,'');
	var h=hashes.split('&'),hash,vars=[];
	for(var i=0;i<h.length;i++){
		hash=h[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]]=hash[1];
	}
	var id=vars['Did'],tipo=(vars['Dtipo']=='serie')?'series':'peliculas';
	window.location.href= decodeURIComponent(id)+'?url='+encodeURIComponent(a);
}
function styleButton(b){
	b.className='';
	b.style.background="#3176bb";
	b.style.borderRadius='2px';
	b.style.MozBorderRadius='2px';
	b.style.fontWeight="bold";
	b.style.padding="8px 15px";
	b.style.color="#FFFFFF";
	b.style.textDecoration="none";
	b.style.display="inline";
	b.style.fontWeight='bold';
	b.style.border=0;
	b.style.fontSize='11px';
	b.style.fontFamily='Helvetica, Arial';
	b.style.cursor='pointer';
	b.style.fontStyle='normal';
	b.style.textTransform='uppercase';
	b.style.textShadow='0 1px 0 #000000';
}